﻿#region Copyright
/// <copyright>
/// Copyright (c) 2008 Ilia Shramko.
/// Released under the terms of the GNU General Public License.
/// </copyright>
#endregion

using System;
using System.Collections.Generic;
using System.Text;

using Osh.Media;

namespace Osh.Qwerty
{
	public class Folder : MediaFolder
	{
		private Guid _id;
		private int? _serverId;

		public Folder(IMediaTree tree, Guid id, int serverId, string name)
			: this(tree, id, serverId, name, new List<IMedia>())
		{
		}

		public Folder(IMediaTree tree, Guid id, int? serverId, string name, List<IMedia> channels)
			: base(tree, id.ToString(), name, channels)
		{
			_id = id;
			_serverId = serverId;
		}

		internal Guid Guid
		{
			get { return _id; }
		}

		internal int? ServerId
		{
			get { return _serverId; }
		}

		internal IList<IMedia> Channels
		{
			get { return base.ItemList; }
		}

		internal void Update(Folder newFolder)
		{
			ChannelDatabase database = (this.Tree as Tree).ChannelDatabase;

			this.Name = newFolder.Name;

			this.Channels.Clear();
			foreach(Channel newChannel in newFolder.Channels)
			{
				Channel channel;
				if(database.TryGetChannelByServerId(newChannel.ServerId.Value, out channel))
					this.Channels.Add(channel);
			}
		}
	}
}
